/// 锻炼信息模型（从API获取）
class ExerciseInfo {
  final int id;
  final String exerciseName;
  final String exerciseLogo;
  final String triggerType; // 1=普通, 2=GPS, 3=室内/室外
  final String? createTime;

  ExerciseInfo({
    required this.id,
    required this.exerciseName,
    required this.exerciseLogo,
    required this.triggerType,
    this.createTime,
  });

  factory ExerciseInfo.fromJson(Map<String, dynamic> json) {
    return ExerciseInfo(
      id: json['id'] ?? 0,
      exerciseName: json['exerciseName'] ?? '',
      exerciseLogo: json['exerciseLogo'] ?? '',
      triggerType: json['triggerType']?.toString() ?? '1',
      createTime: json['createTime'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'exerciseName': exerciseName,
      'exerciseLogo': exerciseLogo,
      'triggerType': triggerType,
      if (createTime != null) 'createTime': createTime,
    };
  }

  /// 是否支持GPS
  bool get hasGps => triggerType == '2' || triggerType == '3';

  /// 是否室内运动
  bool get isIndoor => exerciseName.contains('室内');

  /// 是否室外运动
  bool get isOutdoor => exerciseName.contains('室外') || exerciseName.contains('GPS');

  @override
  String toString() {
    return 'ExerciseInfo(id: $id, name: $exerciseName, triggerType: $triggerType)';
  }
}
